package com.ruoyi.mybatchscheduling.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mybatchscheduling.domain.BatchInfo;
import com.ruoyi.mybatchscheduling.service.IBatchInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 批次信息Controller
 * 
 * @author chenxin
 * @date 2024-01-27
 */
@RestController
@RequestMapping("/batch")
public class BatchInfoController extends BaseController
{
    @Autowired
    private IBatchInfoService batchInfoService;

    /**
     * 查询批次信息列表
     */
    @RequiresPermissions("mybatchscheduling:batch:list")
    @GetMapping("/list")
    public TableDataInfo list(BatchInfo batchInfo)
    {
        startPage();
        List<BatchInfo> list = batchInfoService.selectBatchInfoList(batchInfo);
        return getDataTable(list);
    }

    /**
     * 导出批次信息列表
     */
    @RequiresPermissions("mybatchscheduling:batch:export")
    @Log(title = "批次信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BatchInfo batchInfo)
    {
        List<BatchInfo> list = batchInfoService.selectBatchInfoList(batchInfo);
        ExcelUtil<BatchInfo> util = new ExcelUtil<BatchInfo>(BatchInfo.class);
        util.exportExcel(response, list, "批次信息数据");
    }

    /**
     * 获取批次信息详细信息
     */
    @RequiresPermissions("mybatchscheduling:batch:query")
    @GetMapping(value = "/{批次ID}")
    public AjaxResult getInfo(@PathVariable("批次ID") Long 批次ID)
    {
        return success(batchInfoService.selectBatchInfoBy批次ID(批次ID));
    }

    /**
     * 新增批次信息
     */
    @RequiresPermissions("mybatchscheduling:batch:add")
    @Log(title = "批次信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BatchInfo batchInfo)
    {
        return toAjax(batchInfoService.insertBatchInfo(batchInfo));
    }

    /**
     * 修改批次信息
     */
    @RequiresPermissions("mybatchscheduling:batch:edit")
    @Log(title = "批次信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BatchInfo batchInfo)
    {
        return toAjax(batchInfoService.updateBatchInfo(batchInfo));
    }

    /**
     * 删除批次信息
     */
    @RequiresPermissions("mybatchscheduling:batch:remove")
    @Log(title = "批次信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{批次IDs}")
    public AjaxResult remove(@PathVariable Long[] 批次IDs)
    {
        return toAjax(batchInfoService.deleteBatchInfoBy批次IDs(批次IDs));
    }
}
